﻿@using iOSClub.WebSite.IdentityModels
@using Microsoft.AspNetCore.Components.Authorization
@inject NavigationManager NavigationManager
@inject AuthenticationStateProvider authStateProvider
@inject MessageService MessageService


<Menu Theme="MenuTheme.Light"
      Class="@Class"
      Style="@Style"
      OnMenuItemClicked="OnMenuItemClicked"
      Mode="MenuMode.Inline">

    <MenuItemGroup Class="group-block">
        <TitleTemplate>
            <div class="group-title">
                个人中心
            </div>
        </TitleTemplate>
        <ChildContent>
            <MenuItem RouterLink="/Centre" RouterMatch="NavLinkMatch.All">
                <Icon Type="home" Theme="outline"/>
                <span class="nav-text">主页</span>
            </MenuItem>
            <MenuItem RouterLink="/Centre/PersonalData" RouterMatch="NavLinkMatch.All">
                <Icon Type="user" Theme="outline"/>
                <span class="nav-text">成员信息</span>
            </MenuItem>
        </ChildContent>
    </MenuItemGroup>

    @if (State != "Member" && State != "Founder")
    {
        <MenuItemGroup Class="group-block">
            <TitleTemplate>
                <div class="group-title">
                    部门和资源
                </div>
            </TitleTemplate>
            <ChildContent>
                <MenuItem RouterLink="/Centre/Department" RouterMatch="NavLinkMatch.All">
                    <Icon Type="project" Theme="outline"/>
                    <span class="nav-text">社团部门</span>
                </MenuItem>
                <MenuItem RouterLink="/Centre/Resource" RouterMatch="NavLinkMatch.All">
                    <Icon Type="file-text" Theme="outline"/>
                    <span class="nav-text">社团资源</span>
                </MenuItem>
                <MenuItem RouterLink="/Centre/Article" RouterMatch="NavLinkMatch.All">
                    <Icon Type="file-text" Theme="outline"/>
                    <span class="nav-text">社团文章</span>
                </MenuItem>
            </ChildContent>
        </MenuItemGroup>
       
    }

    @if (State.Contains("Minister") || State == "President" || State == "Founder")
    {
        <MenuItemGroup Class="group-block">
            <TitleTemplate>
                <div class="group-title">
                    数据中心
                </div>
            </TitleTemplate>
            <ChildContent>
                <MenuItem RouterLink="/Admin/MemberData" RouterMatch="NavLinkMatch.All">
                    <Icon Type="team" Theme="outline"/>
                    <span class="nav-text">成员数据</span>
                </MenuItem>
                <MenuItem RouterLink="/Admin/Env" RouterMatch="NavLinkMatch.All">
                    <Icon Type="setting" Theme="outline"/>
                    <span class="nav-text">其他数据</span>
                </MenuItem>
            </ChildContent>
        </MenuItemGroup>
    }

    <MenuItemGroup Class="group-block">
        <TitleTemplate>
            <div class="group-title">
                其他
            </div>
        </TitleTemplate>
        <ChildContent>
            <MenuItem OnClick="Logout" RouterMatch="NavLinkMatch.All">
                <Icon Type="logout" Theme="outline"/>
                <span class="nav-text">退出登录</span>
            </MenuItem>
        </ChildContent>
    </MenuItemGroup>
</Menu>

@code {
    [Parameter] public string State { get; set; } = "Member";
    [Parameter] public string Style { get; set; } = "";
    [Parameter] public string Class { get; set; } = "";
    [Parameter] public EventCallback OnMenuItemClicked { get; set; }

    private async Task Logout()
    {
        var provider = (AbsProvider)authStateProvider;
        await MessageService.Success("您已注销");
        await provider.Logout();
        NavigationManager.NavigateTo("");
    }

}

<style>
    .group-block{
        padding: 10px;
    }

    .group-title {
        padding-bottom: 10px;
        border-bottom: 1px solid #ededed;
    }
</style>